<?php

namespace Admin\Controller;

use Think\Controller;

class SettingController extends ComController {

    public function setCharge() {
        
    }

    public function index() {
        $b = M('wechat');
        $w = array();
        $w['id'] = 1;
        $lwechat = $b->where($w)->find();
        $this->assign('lwechat', $lwechat);
        $this->display();
    }

    public function set_signal() {
        $b = M('wechat');
        $w = array();
        $w['id'] = 1;
        $lwechat = $b->where($w)->comment('wechat查询')->find();
        $this->assign('wechat', $lwechat);
        $this->display();
    }

    public function protocol() {
        if (IS_POST) {
            $data = I('post.data');
            $data = serialize($data);
            $a = D('Setting')->save(array('k' => 'protocol', 'v' => $data));
//            D('Setting')->cleanCache();
            $this->success('设置成功', U('setting/protocol'));
        } else {
            $protocol = D('Setting')->getByK('protocol');
            $protocol = unserialize($protocol['v'])['protocol'];
            $protocol = html_entity_decode($protocol);
            $this->assign('protocol', $protocol);
            $this->display();
        }
    }

    public function userprotocol() {
        if (IS_POST) {
            $data = I('post.data');
            $data = serialize($data);
            $a = D('Setting')->save(array('k' => 'userprotocol', 'v' => $data));
//            D('Setting')->cleanCache();
            $this->success('设置成功', U('setting/userprotocol'));
        } else {
            $protocol = D('Setting')->getByK('userprotocol');
            $protocol = unserialize($protocol['v'])['userprotocol'];
            $protocol = html_entity_decode($protocol);
            $this->assign('userprotocol', $protocol);
            $this->display();
        }
    }

    public function wechat_update() {
        $post = I('post.');

        $w['oldid'] = $post['oldid'];
        $w['wxnumber'] = $post['wxnumber'];
        $w['wxnickname'] = $post['wxnickname'];
        $w['appid'] = $post['appid'];
        $w['appsecret'] = $post['appsecret'];
        $w['iosdurl'] = $post['iosdurl'];
        $w['androiddurl'] = $post['androiddurl'];
        $w['jsurl'] = $post['jsurl'];
        $w['serurl'] = $post['serurl'];
        foreach ($w as $key => $value) {
            if (isset($value)) {
                $data[$key] = $value;
            }
        }
        $b = M('wechat');
        $i = $b->where(array('id' => 1))->save($data);
        if ($i > 0) {
            $this->success('编辑书籍成功');
        } else {
            $this->error('编辑书籍失败，请重试');
        }
    }

}
